home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr47 / qfml10.zip / EXAMPLE2.CPP < prev    next >
C/C++ Source or Header  |  1995-01-30  |  6KB  |  180 lines

  1. /*********************************************************************
  2. ** QFML DEMO :
  3. **   ALTHOUGH THIS LISTING CAN'T BE MODIFIED, IT SHOWS HOW QFM WORKS.
  4. **     IT LOADS TWO 320x200x256 IMAGES INTO THE MEMORY ALLOCATED BY
  5. **   OPENMEM AND MOVES A WINDOW IN THEM WICH IS SHOWN CAN SEE ON THE
  6. **   SCREEN.
  7. **     TO SEE A DEATILED EXPLANATION OF QFM'S FUNCTIONS READ DE READ-
  8. **   ME FILE AND THE QFML.H FILE.
  9. **
  10. **   THE PAN IMAGE FORMAT IS JUST A QUICK RAW FORMAT.
  11. **   THE VIDEO.H AND VIDEO.C HAVE NOT BEEN INCLUDED IN THIS PACKAGE
  12. ** BUT THEY ARE NOT REALLY  IMPORTANT AS IT IS JUST A SIMPLE DRIVER
  13. ** FOR MCGA MODE.
  14. **
  15. ** THIS WAS COMPILED USING A BORLANDC(3.1) PROJECT, TRANSLATED INTO A MAKE
  16. ** WITH BORLAND'S PRJ2MAK AND ADDING /3 TO TLINK LINE IN THE MAKE.
  17. ** (C) RENDER OF ACC TEAM (1995)
  18. *********************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <conio.h>
  23. #include "video.h"
  24. #include "qfml.h"                // To use QFML functions include this file
  25.                                  // and link with qfml.obj
  26.  
  27. #define word unsigned int
  28. #define dword unsigned long int
  29. #define byte unsigned char
  30. #define NUM 2                    // Initially there were ten pans but the NET
  31.                                  // costs money
  32.  
  33. //-------------------------------------------------
  34. // Just a function to load the palette to use
  35.  
  36. void
  37. LoadMCGAPalette3(char *nombre,byte *colores,char extendido)
  38. {
  39.     FILE    *f;
  40.     int    b,c,a;
  41.  
  42.     f=fopen(nombre,"rb");
  43.     if (!ferror(f)){
  44.         if (extendido)
  45.                 colores[0]=getc(f);
  46.         a=0;
  47.         do{
  48.             colores[a]=getc(f);
  49.             a=a+1;
  50.         }while ( (!feof(f)) && (a<768) );
  51.         b=FP_SEG(colores);
  52.         c=FP_OFF(colores);
  53.         asm{
  54.                 mov    ah,0x10
  55.                 mov     al,0x12
  56.                 mov    bx,0
  57.                 mov    cx,256
  58.                 mov    dx,c
  59.                 mov     es,b
  60.  
  61.                 int    0x10
  62.         }
  63.         fclose(f);
  64.   }else printf("\  Error: File error.\n");
  65. }
  66.  
  67. //----------------------------------------------------
  68. // Just a function to rotate the palette (very simple)
  69.  
  70. void
  71. CicloPal(byte *colores)
  72. {
  73.     word b,c;
  74.  
  75.     for (int a=3;a<768;a++)
  76.         colores[a]++;
  77.  
  78.  
  79.     b=FP_SEG(colores);
  80.     c=FP_OFF(colores);
  81.     asm{
  82.             mov    ah,0x10
  83.             mov     al,0x12
  84.             mov    bx,0
  85.             mov    cx,256
  86.             mov    dx,c
  87.             mov     es,b
  88.  
  89.             int    0x10
  90.     }
  91. }
  92.  
  93. //============================================================
  94. // Look carefully at this one, this is the IMPORTANT BIT.
  95.  
  96. void
  97. main(void)
  98. {
  99.     dword First_addr;                 // Keeps starting QFM's memory address
  100.     dword MCGA_off;                   // Plane address of video mem.
  101.     dword num_ks;                     // Keeps the amount of K's reserved
  102.     dword p5;                         // Auxiliar
  103.  
  104.     dword a;                          // Used as an offset to First_addr
  105.     byte pal[768];                    // For the palette to rotate
  106.  
  107.     char *cads[]={                    // File names
  108.         "screen01.pan",
  109.      "screen02.pan",
  110.     };
  111.  
  112.  
  113.     // First of all start QFM before leaving textmode
  114.     if (StartPL()) exit(1);
  115.  
  116.     // Then open the whole mem after the first Megabyte.
  117.     if (OpenMem()) {
  118.       LeavePL();           // Leave QFM mode before leaving your code.(ALWAYS)
  119.       exit(1);
  120.     }
  121.  
  122.     // We get the amount of memory available
  123.     num_ks=GiveAmo();
  124.     if (num_ks<130) {      // We need a minimum of 128 k
  125.       CloseMem();          // Close mem. before leavinf QFM. (ALWAYS)
  126.       LeavePL();           // Leave QFM mode before leaving your code.(ALWAYS)
  127.     }
  128.     printf ("Available memory after first Mgb. (Kbytes):%lu\n",num_ks);
  129.  
  130.     // Then we need the starting address of this block in plane
  131.     // memory. Observe it will always be after position 1048576 (1Mb)
  132.     First_addr=GiveSta();
  133.  
  134.     // Wait just a little before leaving text mode
  135.     delay(50*50);
  136.     PutVideo(0x13);        // This is a <video.h> function. It starts 13h mode
  137.  
  138.     // We need the starting address of video ram. As a example I use the
  139.     // VirToPL function to translate a seg:off mode to a 4Gb offset
  140.     MCGA_off=VirToPL(0xa000,0);       //MCGA_off MCGA
  141.  
  142.     // Then we load the two screens, one after the other.
  143.     // Observe that in 320x200x256 mode the screen is just
  144.     // an array of 64000 bytes containg each the color register of that
  145.     // pixel. For Example color of pixel x=29,y=30 is just offset
  146.     // y*320+x in the segment A000h
  147.     for(a=0;a<NUM;a++){
  148.       LoadMCGAScreen(cads[a],1);      // This is a <video.h> function.It loads
  149.                                       // a PAN and puts it into video memory.
  150.       p5=First_addr+64000L*a;         // We calculate the 4Gb offset were we
  151.       Pl2Pl(MCGA_off,p5,64000L);      // will copy the 64000 array to
  152.     }
  153.  
  154.     LoadMCGAPalette3(cads[0],pal,1);  // Just Load a palette
  155.  
  156.     ClearVideo();                     // Clear the screen
  157.  
  158.     // repeat this bucle until a key is hit
  159.     for (;!kbhit();){
  160.  
  161.         for (a=0;( (a<(NUM-1)*64000)&&(!kbhit()) );a+=320){
  162.             Pl2Pl(First_addr+a,MCGA_off,64000L);    // Show a part of the two screens
  163.             CicloPal(pal);            // Rotate the palette
  164.         }
  165.         for (a=(NUM-1)*64000L;( (a>1280)&&(!kbhit()) );a-=1280){
  166.             Pl2Pl(First_addr+a,MCGA_off,64000L);    // Show a part of the two screens
  167.             CicloPal(pal);            // Rotate the palette
  168.         }
  169.     }
  170.  
  171.     // And leave
  172.     QuitVideo();                      // Quit video mode
  173.     getch();                          // Clear keyboard buffer
  174.  
  175.     // Close openned mem. before living
  176.     CloseMem();
  177.  
  178.     // Leave QFM before termination
  179.     LeavePL();
  180. }